package kerjodando.casper.util;

public class StringUtil {
	public static final String EMPTY_STRING="";
	public static boolean isEmptyOrNull(String s)
	{
		return s==null || s.length()==0;
	}

	/*
	 * Convert the file size to string
	 * 
	 */
	static public String fileSize2Str(double dSize) {
		String[] SUFFIXS = { "Bs", "KB", "MB", "GB", "TB" };
		double currentSize = dSize;
		int iIndexOfSuffix = 0;
		for (; dSize > ConstantUtil.KBYTES && iIndexOfSuffix <= 4; iIndexOfSuffix++) {
			dSize = dSize / ConstantUtil.KBYTES;
		}
		// converting to string and keeping 1 digit after point
		int lSize = (int) ((currentSize / Math.pow(2, iIndexOfSuffix * 10)) * 10);
		short lAfterPoint = (short) (lSize % 10);
		String sRet = String.valueOf(lSize / 10);
		if (lAfterPoint != 0)
			sRet += '.' + String.valueOf(lAfterPoint);
		// size plus suffix
		return sRet + SUFFIXS[iIndexOfSuffix];
	}
}
